package com.community.system.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.enums.BusinessType;
import com.community.system.domain.PatrolCategory;
import com.community.system.service.IPatrolCategoryService;
import com.community.common.utils.poi.ExcelUtil;
import com.community.common.core.page.TableDataInfo;

/**
 * categoryController
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/category")
public class PatrolCategoryController extends BaseController
{
    @Autowired
    private IPatrolCategoryService patrolCategoryService;

    /**
     * 查询category列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatrolCategory patrolCategory)
    {
        startPage();
        List<PatrolCategory> list = patrolCategoryService.selectPatrolCategoryList(patrolCategory);
        return getDataTable(list);
    }

    /**
     * 导出category列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "category", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatrolCategory patrolCategory)
    {
        List<PatrolCategory> list = patrolCategoryService.selectPatrolCategoryList(patrolCategory);
        ExcelUtil<PatrolCategory> util = new ExcelUtil<PatrolCategory>(PatrolCategory.class);
        util.exportExcel(response, list, "category数据");
    }

    /**
     * 获取category详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(patrolCategoryService.selectPatrolCategoryByCategoryId(categoryId));
    }

    /**
     * 新增category
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "category", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatrolCategory patrolCategory)
    {
        return toAjax(patrolCategoryService.insertPatrolCategory(patrolCategory));
    }

    /**
     * 修改category
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "category", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatrolCategory patrolCategory)
    {
        return toAjax(patrolCategoryService.updatePatrolCategory(patrolCategory));
    }

    /**
     * 删除category
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "category", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(patrolCategoryService.deletePatrolCategoryByCategoryIds(categoryIds));
    }
}
